(define (sum term a next b)
    (if (> a b)
        0
        (+ (term a)
           (sum term (next a) next b))))

(define (simpson-sum f a b n)
    (define (h a b n) (/ (- b a) n))
    (define (simpson-next1 x)
        (+ x (h a b n)))
    (define (simpson-next2 x)
        (+ x (*  2 (h a b n))))
    (/  (*
            (+ (* 2 (+ (sum f a simpson-next1 b)
                       (sum f a simpson-next2 b)
                       ))
                (- 0 (f a))
                (- 0 (f b)))
            (h a b n))
        3.0))
